/*
 * StartApp.java
 *
 * Created on May 6, 2005, 11:30 AM
 */
package com.bff.slimserver.musicjukebox.lib;

import com.bff.slimserver.music.exceptions.PlayerException;
import com.bff.slimserver.musicjukebox.ui.MainFramePlayer;
import com.bff.slimserver.musicjukebox.ui.SplashPropertiesFrame;
import com.bff.slimserver.musicjukebox.ui.SplashScreen;
import com.bff.slimserver.utils.Resources;
import com.bff.startup.StartUpProperties;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author Bill
 */
public class StartSqueeze {

    /** Creates a new instance of StartApp */
    public StartSqueeze() {
    }

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            UIManager.put("Slider.paintValue", Boolean.FALSE);
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        } catch (UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }

        runApp();
    }

    public static void runApp() {
        if (checkSettings()) {
            SplashScreen sp = null;
            try {
                sp = new SplashScreen(true);
                new MainFramePlayer(sp);
            } catch (Exception e) {
                e.printStackTrace();

                if (e instanceof PlayerException) {
                    //custom title, error icon
                    JOptionPane.showMessageDialog(null,
                            Resources.getMessage(Resources.LABEL_KEY.ERROR_PLAYER_TEXT),
                            Resources.getMessage(Resources.LABEL_KEY.ERROR_PLAYER_TITLE),
                            JOptionPane.ERROR_MESSAGE);
                    StartUpProperties.getInstance().endWriter();
                    System.exit(0);
                }
            }
        } else {
            SplashPropertiesFrame spf = new SplashPropertiesFrame();
            spf.setVisible(true);
        }
    }

    private static boolean checkSettings() {
        if (JukeboxProperties.exists()) {
            return (true);
        }
        return (false);
    }
}
